原帖地址：[http://blog.leanote.com/post/dawnmagnet/lc1190](http://blog.leanot
e.com/post/dawnmagnet/lc1190)
# 题目
<div class="notranslate"><p>给出一个字符串&nbsp;<code>s</code>（仅含有小写英
文字母和括号）。</p>
<p>请你按照从括号内到外的顺序，逐层反转每对匹配括号中的字符串，并返回最终的结
果。</p>
<p>注意，您的结果中 <strong>不应</strong> 包含任何括号。</p>
<p>&nbsp;</p>
<p><strong>示例 1：</strong></p>
<pre><strong>输入：</strong>s = "(abcd)"
<strong>输出：</strong>"dcba"
</pre>
<p><strong>示例 2：</strong></p>
<pre><strong>输入：</strong>s = "(u(love)i)"
<strong>输出：</strong>"iloveu"
</pre>
<p><strong>示例 3：</strong></p>
<pre><strong>输入：</strong>s = "(ed(et(oc))el)"
<strong>输出：</strong>"leetcode"
</pre>
<p><strong>示例 4：</strong></p>
<pre><strong>输入：</strong>s = "a(bcdefghijkl(mno)p)q"
<strong>输出：</strong>"apmnolkjihgfedcbq"
</pre>
<p>&nbsp;</p>
<p><strong>提示：</strong></p>
<ul>
    <li><code>0 &lt;= s.length &lt;= 2000</code></li>
    <li><code>s</code> 中只有小写英文字母和括号</li>
    <li>我们确保所有括号都是成对出现的</li>
</ul>
</div>
# 思路分析
这是一道字符串处理题，从题目中的意思可以得出，括号内的文字需要翻转。
如果我们使用的是边处理边翻转，如果遇到形式如`"(((((abcdefg)))))"`的字符串就会
翻转非常多次数，复杂度达到了$O(N^2)$，其中$N$为字符串长度。